home *** CD-ROM | disk | FTP | other *** search
- Unit STRTOOL;
-
- Interface
- Uses Dos;
-
- type Str3 = String[3];
- Str5 = string[5];
- Str8 = string[8];
- Str10 = string[10];
- Str15 = string[15];
- Str30 = string[30];
- Str40 = string[40];
- Str80 = string[80];
- Str64 = string[64];
- Str255 = string[255];
- CharSet =set of Char;
-
- Const Alphas : Charset = ['A'..'Z','a'..'z','0'..'9',
- '-','$','#','&','_'];
- Term : CharSet = [^E,^I,^M,^Q,^X,^Z,#27];
- DOSseparators : Charset = ['/','\', ':','*','.'];
- Esc = #27;
- Nul = #0;
-
- Procedure SetSearchEnvVar(Name:Str15);
-
- Function SearchFile(F:PathStr):PathStr;
-
- FUNCTION Center (satz : Str80;widh : Integer): Str80;
-
- Procedure UPstr(Var S:String);
-
- Function UpcaseStr(S : Str80) : Str80;
-
- Function ConstStr(C : Char; N : Integer) : Str80;
-
- Procedure ProcessFileName(var FilePath,FileName : PathStr);
-
- function FileExists(Name: PathStr): Boolean;
-
- function IsReadOnly(Name: PathStr): Boolean;
-
- function PathExists(Name: PathStr): Boolean;
-
- Procedure NormFname(Var D:PathStr);
-
- Procedure RemoveSlash(Var P:PathStr);
-
- Function RandomFileName(P:PathStr;Ext:ExtStr):PathStr;
-
- implementation
-
- Const Env_VarStr:Str15='GEDDY';
-
- Procedure SetSearchEnvVar(Name:Str15);
- begin
- UpStr(Name);
- Env_VarStr:=Name;
- end;
-
- Function SearchFile(F:PathStr):PathStr;
- Var Name :PathStr;
- begin
- Name:=Fsearch(F,GetEnv(Env_VarStr));
- If Name='' then SearchFile:=F else SearchFile:=Name;
- end;
-
- FUNCTION Center (satz : Str80;widh : Integer): Str80;
- VAR L,R,C,S : BYTE;
- temp : String;
- BEGIN (* Center *)
- IF length(satz)>widh THEN
- Temp := satz
- ELSE
- BEGIN
- Temp := satz;
- C := length(satz);
- S := widh-C;
- L := S div 2;
- R := L + (S mod 2);
- FOR C := 1 TO L DO Temp := ' '+Temp;
- FOR C := 1 TO R DO Temp := Temp+' ';
- END;
- Center := Temp;
- END; (* Center *)
-
- Procedure UPstr(Var S:String);
- var
- P : Integer;
- begin
- for P := 1 to Length(S) do
- S[P] := Upcase(S[P]);
- end;
-
-
- Function UpcaseStr(S : Str80) : Str80;
- (* Umwandlung in Großbuchstaben *)
- var
- P : Integer;
- begin
- for P := 1 to Length(S) do
- S[P] := Upcase(S[P]);
- UpcaseStr := S;
- end;
-
- Function ConstStr(C : Char; N : Integer) : Str80;
- (* Erzeugt String mit N gleichen Zeichen *)
- var
- S : string[80];
- begin
- if N < 0 then N := 0;
- If N>Pred(SizeOf(Str80)) then N:=Pred(Sizeof(Str80));
- Fillchar(S[1],N,Byte(C));
- S[0] := Chr(N);
- ConstStr:=S;
- end;
-
- procedure ProcessFileName(var FilePath,FileName : PathStr);
-
- Const Backslash='\';
- var
- TmpDir : Str64;
- begin
- Tmpdir:=Filepath;
- If (Length(tmpdir)>0) and (Tmpdir[length(Tmpdir)]<> Backslash) Then
- Tmpdir:=Tmpdir+Backslash;
- Filename:=Tmpdir+Filename;
- end;
-
- function FileExists(Name: PathStr): Boolean;
- var
- SR: SearchRec;
- begin
- FindFirst(Name, 0, SR);
- FileExists := (DosError = 0) and ((SR.Attr and Directory)=0);
- end;
-
- function IsReadOnly(Name: PathStr): Boolean;
- var
- SR: SearchRec;
- begin
- FindFirst(Name, 0, SR);
- IsReadOnly := (DosError = 0) and ((SR.Attr and ReadOnly)>0);
- end;
-
- function PathExists(Name: PathStr): Boolean;
- var actualPath :PathStr;
- begin
- Removeslash(Name);
- {$I-}
- GetDir(0,actualpath);
- ChDir(Name);
- PathExists:=Ioresult=0;
- Chdir(actualpath);
- If Ioresult=0 then Exit;
- end;
-
- Procedure NormFname(Var D:PathStr);
- begin
- D:=Fexpand(D);
- Upstr(D);
- RemoveSlash(D);
- end;
-
- Procedure RemoveSlash(Var P:PathStr);
- begin
- If (P[0]>#3) and (P[Byte(P[0])]='\') then Dec(Byte(p[0]));
- end;
-
- Function RandomCh:Char;
- Var I:Word;
- begin
- I:=Random(36);
- If I>25 then
- RandomCh:=Chr(48-26+I)
- else
- RandomCh:=Chr(65+I);
- end;
-
- Function RandomFileName(P:PathStr;Ext:ExtStr):PathStr;
- Var Name :Str64;
- F :File;
- I :Integer;
- Err,Err1 :Word;
- begin
- Repeat
- Name:='$2345678'+Ext;
- For I:=2 to 8 do Name[I]:=RandomCh;
- ProcessFilename(P,Name);
- until Not FileExists(Name);
- RandomFileName:=Name;
- end;
-
-
- end.
-